package com.krain.ddbb.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Toast;

import com.krain.ddbb.activity.OrderDetailActivity;
import com.krain.ddbb.activity.OrderDetailActivity_;
import com.krain.ddbb.activity.RobOrderActivity_;
import com.krain.ddbb.base.APP;
import com.krain.ddbb.constant.Constant;

import org.json.JSONException;
import org.json.JSONObject;

import cn.jpush.android.api.JPushInterface;

/**
 * Class description
 * 极光推送的广播接收器
 * @author yamin
 * @date 2016/2/1 上午 11:49
 */
public class JpushReceiver extends BroadcastReceiver {
    private final int STATUS_ORDERDETAIL = 1;//进入订单详情的状态码
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals("cn.jpush.android.intent.NOTIFICATION_OPENED")){
            Bundle bundle = intent.getExtras();
            String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);
            try {
                JSONObject object = new JSONObject(extras);
                if (object.optInt("status") == STATUS_ORDERDETAIL){
                    Intent intent1 = new Intent(context,OrderDetailActivity_.class);
                    intent1.putExtra("id",object.optString("order_id"));
                    intent1.putExtra("type",object.optInt("type"));
                    intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    context.startActivity(intent1);
                }else {
                    Intent intent2 = new Intent(context, RobOrderActivity_.class);
                    intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    intent2.putExtra("oid",object.optString("order_id"));
                    context.startActivity(intent2);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }
}
